/**********************************************************************************
Copyright (C), by AppleCai
Project                      : Study Kernel driver
Description                  : User Application for cdev
History                      :
CPU and Compiler             : AM335x,GCC
GenDate                      : 2020-11-14
OwnerBy                      : Apple Cai
**********************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include "stdlib.h"
#include "string.h"

#define CHIP                "/dev/AppleEEP"
#define CHIP_ADDR           0x51
int main(int argc,char **argv) 
{
 int fd =open(CHIP, O_RDWR);
 if (fd< 0) {
   printf("open"CHIP"failed\n");
   goto exit;
 }

 unsigned char  rddata=0x0;
 unsigned char  wrdata=0x0;   
 int ret =0;                       
 if(strcmp(argv[1], "r") == 0)
 {
   printf("readdata return:%d\n", read(fd, &rddata, 1));
   printf("rddata:0x%x\n", rddata);
 }
 else if(strcmp(argv[1], "w") == 0)
 {
   wrdata = atoi(argv[2]);
   printf("writeaddress return: %d\n",write(fd, &wrdata, 1));      
   printf("wrdata:0x%x\n", wrdata); 
 }  
 else
 {
  printf("Please add parameter again,r is read,w is write and add the value,too\n");
}

close:
close(fd);
exit:
return 0;

}